
/**
 * Created by Administrator on 2017/2/22.
 */
import {allUrl} from '../scripts/url'
import {Toast,checkLogin,getFormatDateByLong} from '../scripts/tip'

export const  initList =() => {

    var sinceId = -10;
    var pageSize = 10;

    $('.mallDetails').dropload(
        {
            scrollArea: window,
            loadDownFn: function (me) {
                sinceId += 10;

                $.ajax({
                    type: 'GET',
                    url: '' + allUrl() + 'mall/queryProductList?sinceId=' + sinceId + '&pagesize=' + pageSize ,
                    dataType: 'json',
                    success: function (data) {

                        if(data.head.returnCode===0){
                                  var result=[];
                            if(data.body){
                                result=data.body.productList;
                            }else {
                                result=[]
                            }
                            getData(result,me)
                        }else {
                            Toast(data.head.returnMsg,2000,'');
                        }
                    }
                })
            }
        }
    )
};


function  getData(reult,me){

    var str='';
    var productId,productUrl;

    if(reult.length>0){
        for(var i=0;i<reult.length;i++){

            productId=reult[i].productId;
            productUrl=reult[i].productUrl;

            str+='<li>' +
                '<a href="#/mall/productDetails?productId='+productId+'" style="background: url('+productUrl+')"></a>' +
                '</li>'
        }
    }else {
        // 锁定
        me.lock();
        // 无数据
        me.noData();
    }
        // 插入数据到页面，放到最后面

        $('.mallDetails ul').append(str);

        // 每次数据插入，必须重置
        me.resetload();
}



